﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimeS : MonoBehaviour {

    /*
    void Start()
    {

        System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
        System.DateTime nowTime = System.DateTime.Now;
        long unixTime = (long)System.Math.Round((nowTime - startTime).TotalMilliseconds, System.MidpointRounding.AwayFromZero);
        
    }
    */
    /// <summary>
    /// 时间戳转为C#格式时间
    /// </summary>
    /// <param name=”timeStamp”></param>
    /// <returns></returns>
    private System.DateTime GetTime(string timeStamp)
    {
        System.DateTime dtStart = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
        long lTime = long.Parse(timeStamp + "0000000");
        System.TimeSpan toNow = new System.TimeSpan(lTime);
        return dtStart.Add(toNow);
    }
    /// <summary>
    /// DateTime时间格式转换为Unix时间戳格式
    /// </summary>
    /// <param name=”time”></param>
    /// <returns></returns>
    public static ulong ConvertDateTimeInt(System.DateTime time)
    {
        System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
        return (ulong)(time - startTime).TotalSeconds;
    }
}
